package cn.skyquant.quant4j.jforex.sdk.strategy;

import cn.skyquant.quant4j.sdk.util.constant.EAConstants;
import cn.skyquant.quant4j.sdk.enums.CloseType;
import cn.skyquant.quant4j.sdk.enums.TradeDirection;
import cn.skyquant.quant4j.sdk.util.time.CalendarUtils;
import com.dukascopy.api.Instrument;

import java.util.Objects;

public final class CloseRecordDTO {
    public final CloseType closeType;
    public final long time;
    public final String key;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CloseRecordDTO that = (CloseRecordDTO) o;
        return Objects.equals(key, that.key);
    }

    @Override
    public int hashCode() {
        return Objects.hash(key);
    }

    public static final String getKey(String name, int configIndex, Instrument instrument, TradeDirection tradeDirection) {
        return name + EAConstants.split + configIndex + EAConstants.split + instrument.name() + EAConstants.split + tradeDirection.name();
    }

    public CloseRecordDTO(OrderEx orderEx, CloseType closeType, long time) {
        key = getKey(orderEx.name, orderEx.configIndex, orderEx.instrument, orderEx.tradeDirection);
        this.closeType = closeType;
        this.time = time;
    }

    @Override
    public String toString() {
        return key + "=" + closeType + "," + CalendarUtils.formatStandard(time);
    }
}
